<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>
</body>
<script>
    //1、原型继承
  function Animal() {
    console.log("Animal的构造函数被调用")
    this.head = 1
    this.show = function() {
      console.log("head" + this.head)
    }
  }
  Person.prototype = new Animal()
  Person.prototype.constructor = Person

  function Person() {
    console.log("Person的构造函数被调用")
    this.foot = 2
    this.show = function() {
      console.log("head" + this.head + ",foot=" + this.foot)
    }
  }

  function Student(id, name) {
    console.log("Student的构造函数被调用")
    this.id = id
    this.name = name
    this.show = function() {
      return "{id=" + this.id + ",name=" + this.name + ",foot=" + this.foot + ",head=" + this.head + "}"
    }
  }
  //子类的原型是父类实例对象
  Student.prototype = new Person()
  //重置构造函数，避免构造函数的紊乱，否则stu.constructor=Person
  Student.prototype.constructor = Student
  let stu = new Student(1, "tom")
  console.log(stu.constructor)
  app.innerHTML = stu.show()

  //测试数据类型：
  let res = stu instanceof Student
  console.log("stu 是 Student类型吗？--->" + res)
  res = stu instanceof Person
  console.log("stu 是 Person类型吗？--->" + res)
  res = stu instanceof Object
  console.log("stu 是 Oject类型吗？--->" + res)
  res = new Person() instanceof Object
  console.log("new Person() 是 Oject类型吗？--->" + res)

  //从A类型中派生出B类型，B类型拥有A类型的方法和属性，这个过程称B继承A，
  //B称子类 A称父类，任何一个对象的终极父类是Object对象
  //js中的继承是单线继承

  // 父类a b ,子类c (c继承a&&c继承b) c继承b,b继承a 
  // c-->a c-->b ; c--->b--->a
</script>
</html>